package com.basker.pisces.service.constant;

/**
 * 服务相关的常量
 *
 * @author hangwen
 */
public class ServiceConstants {
    public static class Fallback {
        public static class ReasonCode {

            /**
             * 客户端连接服务器错误
             */
            public static final String CONNECT_ERROR = "Connect Error";

            /**
             * 客户端等待服务端响应超时
             */
            public static final String SOCKET_READ_TIMEOUT = "Socket Read Timeout";

            /**
             * 没有找到可用的服务
             */
            public static final String NO_AVAILABLE_SERVER = "No Available Server";

            /**
             * Hystrix超时
             */
            public static final String HYSTRIX_TIMEOUT = "Hystrix Timeout";

            /**
             * Hystrix线程池已耗尽
             */
            public static final String HYSTRIX_THREAD_POOL_FULL = "Hystrix Thread Pool Full";

            /**
             * Hystrix信号量未获取
             */
            public static final String HYSTRIX_SEMAPHORE_NOT_ACQUIRED = "Hystrix Semaphore Not Acquired";

            /**
             * 目标服务不存在
             */
            public static final String SERVICE_404 = "Service 404";

            /**
             * Hystrix熔断器已打开
             */
            public static final String HYSTRIX_CIRCUITBREAKER_OPEN = "Hystrix circuitbreaker Open";

            /**
             * 客户端请求服务时错误
             */
            public static final String CLIENT_INVOKE_EXCEPTION = "Client Invoke Exception";
        }
    }

    /**
     * 消息头常量
     *
     * @author hangwen
     */
    public class MessageHead {

        /**
         * 表示当前系统Id的key
         */
        public static final String APP_ID_KEY = "appId";

        /**
         * 签名认证中表示签名的key
         */
        public static final String SIGN_KEY = "sign";

        /**
         * 签名认证中表示请求时间戳的key
         */
        public static final String SIGN_TIMESTAMP_KEY = "timestamp";

        /**
         * 服务鉴权认证中表示来源系统的key
         */
        public static final String API_AUTH_SOURCE_SYS_KEY = "sourceSys";

        /**
         * 服务鉴权认证中表示令牌值的key
         */
        public static final String API_AUTH_ACCESS_TOKEN_KEY = "accessToken";

        /**
         * 服务鉴权认证中表示令牌类型的key
         */
        public static final String API_AUTH_TOKEN_TYPE_KEY = "tokenType";

        /**
         * 从API网关发来的请求，在消息头中会存在这个参数，用以表示网关层已经通过校验，无须在服务端端再次校验
         */
        public static final String API_AUTH_GATE_WAY_USER_ID_KEY = "apiGateWayUserId";

        /**
         * 表示当前请求语言标识的key
         */
        public static final String LOCAL_KEY = "local";

        /**
         * 当前请求的令牌id
         */
        public static final String TOKEN_ID_KEY = "tokenId";

        /**
         * 当前请求的traceId
         */
        public static final String TRACE_ID_KEY = "traceId";

        /**
         * 当前请求的spanId
         */
        public static final String SPAN_ID_KEY = "spanId";

        /**
         * 当前请求的parentSpanId
         */
        public static final String PARENT_SPAN_ID_KEY = "parentSpanId";
    }

    /**
     * 服务结果的状态码常量
     *
     * @author hangwen
     */
    public static class StatusCode {
        /**
         * API认证中心表示令牌失效的代码
         */
        public static final int API_AUTH_TOKEN_EXPIRED = 1004;

        /**
         * 未通过api授权
         */
        public static final int API_AUTH_VIOLATION = -2000;

        /**
         * 表示未通过JSR303验证的结果值
         */
        public static final int JSR303_VIOLATION = -2001;

        /**
         * 表示hystrix fallback返回的错误
         */
        public static final int HYSTRIX_FALLBACK = -2002;

        /**
         * 没有登录或登录超时
         */
        public static final int LOGINCONTEXT_NOT_FOUND = -2003;

        /**
         * 违反数据签名规则
         */
        public static final int SIGNATURE_VIOLATION = -2004;
    }
}
